package com.zhanqiao.Dao;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import com.zhanqiao.domain.FansBean;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.List;

public class FanDao implements FansDao {

    private DataSource dataSource;
    private QueryRunner queryRunner;

    //查询所有需要的粉丝信息
    @Override
    public List<FansBean> selectAll(String page, String limit) throws SQLException {
        //这里连接数据库给servlet传递值
        //c3p0连接
        Integer p = Integer.valueOf(page);
        Integer l = Integer.valueOf(limit);
        dataSource = new ComboPooledDataSource();
        queryRunner = new QueryRunner(dataSource);
        Object[] pars = {(p-1)*l,l};
        List<FansBean> query = (List<FansBean>) queryRunner.query("select uid,uname,sex,city,signature from user limit ?,?", pars, new BeanListHandler(FansBean.class));
        System.out.println(query.get(0));
        return query;
    }

    //改变用户头像
    @Override
    public int upImages(String url) {
        return 0;
    }

    //修改用户信息
    @Override
    public int updateUser(int id, FansBean userBean) {
        return 0;
    }
}
